#define _CRT_SECURE_NO_WARNINGS 1
#include<ctype.h>
#include<string.h>
#include<assert.h>
#include<stdlib.h>

void reverse( char* left, char* right)
{
	assert(left && right);
	while (left < right)
	{
		char tmp = *left;
		*left = *right;
		*right = tmp;
		++left;
		--right;
	}

}

char* reverseWords(char* s)
{
	int len = strlen(s);
	reverse(s, s + len - 1);
	char* ans = calloc(len + 1, sizeof(char));
	if (!ans)
	{
		perror("calloc");
		exit(1);
	}
	char* ret = ans;
	char* pre = s;
	while (isspace(*pre))
		++pre;
	while (*pre)
	{
		s = pre;
		while (isalnum(*s))
			++s;
		reverse(pre, s - 1);
		while (pre <= s - 1)
			*ans++ = *pre++;
		while (isspace(*pre))
			++pre;
		if (*pre)
			*ans++ = ' ';
	}
	*ans = '\0';
	return ret;
}

int main()
{
	char str[] = "the sky is blue";
	char* ret = reverseWords(str);
	puts(ret);
	free(ret);
	return 0;
}